package com.qs.eggs.utils;

import android.content.Context;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.qs.eggs.R;
import com.qs.eggs.adapter.CitySelectAdapter;
import com.qs.eggs.refresh.utils.TDevice;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/5/9.
 */

public class CityDialogHelper {
    static View mCityView;
    static RecyclerView mCityRecyclerView;
    static AlertDialog dialog;
    public static void getCity(Context context, ArrayList<String> mList, ArrayList<String> mListId,final TextView textView, final TextView tvForId){
        mCityView = LayoutInflater.from(context).inflate(R.layout.dialog_recyclerview_city, null, false);

        mCityRecyclerView=(RecyclerView)mCityView.findViewById(R.id.rv_city);
        CitySelectAdapter provincesAdapter=new CitySelectAdapter(context,mListId,mList);
        mCityRecyclerView.setAdapter(provincesAdapter);
        mCityRecyclerView.setLayoutManager(new LinearLayoutManager(context));
        provincesAdapter.setOnItemClickLitener(new CitySelectAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position, String id, String name) {
                textView.setText(name);
                dialog.dismiss();
                tvForId.setText(id);

            }

            @Override
            public void onItemLongClick(View view, int position) {

            }
        });
        final AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder
                .setView(mCityView);
        dialog=builder.create();
        dialog.setCanceledOnTouchOutside(false);// 设置点击屏幕Dialog不消失
        dialog.show();
        WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
        params.width =(int)(TDevice.getScreenWidth()*0.8);
        params.height = (int)(TDevice.getScreenHeight()*0.7) ;
        dialog.getWindow().setAttributes(params);
    }
}
